# -*- coding: utf-8 -*-
"""
Created on Mon Feb 11 00:32:46 2013

@author: Winand
"""

from general import *

def background_callback(mac_str):
    print "wake callback!", mac_str
    mac = parseDispMacAddr(mac_str)
    if mac:
        dat='\xff'*6 + mac*16
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        broadcast = getBroadcastAddress()
        if broadcast: sock.sendto(dat, (broadcast, 7)) 
        else: error("Cannot wake. Specify broadcast address")
    else: error("Cannot wake. Wrong MAC address")